// 团与车辆分配相关的 HTTP 操作
import http from '@/https/http.js'

/**
 * 分配团到车辆
 * @param {Object} params - 分配参数
 * @param {number} params.groupId - 团ID
 * @param {number} params.vehicleId - 车辆ID
 * @param {string} params.openId - 用户OpenId
 * @returns {Promise} - 返回分配结果
 */
export const assignGroupToVehicle = async (params = {}) => {
    try {
        return await http.post('Mini/Allocate/AssignGroupToVehicle', params)
    } catch (error) {
        console.error('分配团到车辆失败:', error)
        throw error
    }
}

/**
 * 取消团与车辆的分配
 * @param {Object} params - 取消分配参数
 * @param {number} params.groupId - 团ID
 * @param {number} params.vehicleId - 车辆ID
 * @param {string} params.openId - 用户OpenId
 * @returns {Promise} - 返回取消分配结果
 */
export const cancelGroupVehicleAssignment = async (params = {}) => {
    try {
        return await http.post('Mini/Allocate/CancelGroupVehicleAssignment', params)
    } catch (error) {
        console.error('取消分配失败:', error)
        throw error
    }
}

/**
 * 获取已分配的团车关系
 * @param {Object} params - 查询参数
 * @param {string} params.openId - 用户OpenId
 * @returns {Promise} - 返回分配关系列表
 */
export const getGroupVehicleAssignments = async (params = {}) => {
    try {
        return await http.post('Mini/Allocate/GetGroupVehicleAssignments', params)
    } catch (error) {
        console.error('获取分配关系失败:', error)
        throw error
    }
}

export default {
    assignGroupToVehicle,
    cancelGroupVehicleAssignment,
    getGroupVehicleAssignments
}